import 'package:dio/dio.dart';
import '../model/response_data.dart';
/*
static NSString * const proUrl = @"http://api-front.v2.shunliandev.com";  //预发布
static NSString * const lineUrl = @"https://api.shunliandongli.com/v2/front"; //线上
*/

class HttpManager {
  //内部静态的使用
  static final HttpManager _httpMangaer = HttpManager._createManager();

  //外部使用
  static HttpManager get manager => _httpMangaer;

  late BaseOptions _options;
  late Dio _dio;

  HttpManager._createManager() {
    _options = BaseOptions(
      contentType: Headers.jsonContentType,
      responseType: ResponseType.json,
      receiveDataWhenStatusError: false,
      connectTimeout: const Duration(seconds: 30),
      receiveTimeout: const Duration(seconds: 30),
    );
    _dio = Dio(_options);
  }

  addInterceptors(List<Interceptor> interceptors) {
    _dio.interceptors.addAll(interceptors);
  }

  Future<SLRequestData> get({required String path}) async {
    var response = await _dio.get(
      path,
    );
    return response.data;
  }

  Future<SLRequestData> post(
      {required String path, Map<String, dynamic>? params}) async {
    params = params ?? {};
    var response = await _dio.post(path, data: params);

    return response.data;
  }
}
